window.addEventListener('load', function () {
    let tbody = this.document.querySelector('tbody')

    //弹出新增用户的模态框
    let btnAddDiolog = this.document.querySelector('.btnAddDiolog')
    // // 获取新增模态框确认按钮
    // let btnadd = this.document.querySelector('.btnadd')
    // // 获取新增模态框编辑按钮
    // let addModalLabel = this.document.querySelector('#addModalLabel')

    // 一·动态渲染
    function init() {
        axios({
            url: '/student/list'
        }).then(({ data: { data } }) => {
            let htmlStr = ''
            data.forEach(function (value, index) {
                htmlStr += `     <tr>
                <th scope="row">${index + 1}</th>
                <td>${value.name}</td>
                <td>${value.age}</td>
                <td>${value.sex}</td>
                <td>${value.group}</td>
                <td>${value.phone}</td>
                <td>${value.salary}</td>
                <td>${value.ruesalary}</td>
                <td>${value.province + value.city + value.county}</td>
                <td>
                  <button type="button" data-id=${value.id} class="btn btn-primary btn-sm btnedit">修改</button>
                  <button type="button"data-id='${value.id}' class="btn btn-danger btn-sm btndel">删除</button>
                </td>
              </tr>`
            })
            tbody.innerHTML = htmlStr
        })
    }
    init()
    // 二·学员信息的添加
    btnAddDiolog.addEventListener('click', function () {
        // 弹窗
        $('#addModal').modal('show')
    })
})